package com.digitalxpert.jargle.TestGui;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.text.JTextComponent;
public class GlobalMouseListener {
	// private HashMap<Class, PopupMenuListener> dict = new HashMap<Class,
	// PopupMenuListener>();
	PopupMenuListener textComponentListener;
	PopupMenuListener tabListener;
	PopupMenuListener tableListener;
	public GlobalMouseListener(Component c) {
		initListeners();
		changeGlobalMouseListener(c);
	}
	private void initListeners() {
		TextComponentPopupMenu cpMenu = new TextComponentPopupMenu();
		textComponentListener = new PopupMenuListener(cpMenu);
		TabbedPopupMenu tabMenu = new TabbedPopupMenu();
		tabListener = new TabPopupListener(tabMenu);
		
		TablePopupMenu tableMenu = new TablePopupMenu();
		tableListener = new PopupMenuListener(tableMenu);
	}
	private void changeGlobalMouseListener(Component c) {
		if (c instanceof JTextComponent) {
			System.out.println(c.getClass());
			c.addMouseListener(textComponentListener);
		}
		if (c instanceof JTabbedPane) {
			System.out.println(c.getClass());
			c.addMouseListener(tabListener);
		}
		if (c instanceof JTable) {
			System.out.println(c.getClass());
			c.addMouseListener(tableListener);
		}
		if (c instanceof Container) {
			Container cc = (Container) c;
			int l = cc.getComponentCount();
			for (int i = 0; i < l; i++) {
				Component child = cc.getComponent(i);
				changeGlobalMouseListener(child);
			}
		}
	}
}
